﻿@using Microsoft.AspNetCore.Http.Extensions
@using Microsoft.Extensions.Caching.Memory
@using Microsoft.Extensions.DependencyInjection

@inject DemoMenuMeta meta

@{
    var routeValues = ViewContext.RouteData.Values;
    var nodes = meta.ToHierarchicalDataSource(Url, (string)routeValues["controller"], (string)routeValues["action"]);
}

<div class="demo-menu">
    <div id="demo-menu-tree"></div>
    <script>
        $(function() {
            $("#demo-menu-tree").dxTreeView({
                dataSource: @Json.Serialize(nodes),
                dataStructure: "tree",
                itemTemplate: function(data) {
                    return $(document.createElement("a")).attr("href", data.Url).text(data.Text);
                },
                itemsExpr: "@nameof(DemoTreeNode.Items)",
                expandedExpr: "@nameof(DemoTreeNode.Active)",
                selectedExpr: "@nameof(DemoTreeNode.Active)",
                animationEnabled: false,
                focusStateEnabled: false,
                selectNodesRecursive: false,
            });
        });
    </script>
</div>
